package com.fjd.controller;

import com.fjd.entity.Goods;
import com.fjd.entity.MerchandiseInfo;
import com.fjd.result.Result;
import com.fjd.service.ShoppingService;
import com.fjd.vo.Category12VO;
import com.fjd.vo.CategoryVO;
import com.fjd.vo.MerchandiseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController("ShoppingController")
@RequestMapping("/shopping/mall")
@Slf4j
@Api(tags = "商城模块")
public class ShoppingController {
    @Autowired
    private ShoppingService shoppingService;

    @GetMapping("/merchandise/list/{category}")
    @ApiOperation("主页展示商品")
    public Result<List<MerchandiseVO>> listMerchandise(@PathVariable String category){
        List<MerchandiseVO> merchandiseVOList = new ArrayList<>();
        merchandiseVOList =  shoppingService.listByCatergory(category);
        return Result.success(merchandiseVOList);
    }

    @GetMapping("/search")
    @ApiOperation("商品搜索")
    public Result<List<MerchandiseVO>> search(String record){
        shoppingService.addHistoryRecord(record);
        List<MerchandiseVO> merchandiseVOList = shoppingService.search(record);
        return Result.success(merchandiseVOList);
    }

    @GetMapping("/searchhistory")
    @ApiOperation("获取用户历史搜索记录")
    public Result<List<String>> searchHistory(){
        List<String>  records = shoppingService.listHistoryRecord();
        return Result.success(records);
    }

    @DeleteMapping("/delHistory")
    @ApiOperation("删除用户历史搜索记录")
    public Result delSearchHistory(){
        shoppingService.delHistoryRecord();
        return Result.success();
    }

    @GetMapping("/category")
    @ApiOperation("获取商城一级目录")
    public Result<List<CategoryVO>> getCategory(){
        List<CategoryVO> categoryVOList = shoppingService.getCategory();
        return Result.success(categoryVOList);
    }

    @GetMapping("/category12")
    @ApiOperation("获取商城一二级目录")
    public Result<List<Category12VO>> getCategory12(){
        List<Category12VO> categoryVOList = shoppingService.getCategory12();
        return Result.success(categoryVOList);
    }

    @GetMapping("/merchandise/list2/{category}")
    @ApiOperation("根据二级目录展示商品")
    public Result<List<MerchandiseVO>> listMerchandise2(@PathVariable String category){
        List<MerchandiseVO> merchandiseVOList = new ArrayList<>();
        merchandiseVOList =  shoppingService.listByCatergory2(category);
        return Result.success(merchandiseVOList);
    }

}
